package com.example.service;

import com.example.entity.Category;
import com.example.mapper.CategoryMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryService {
    @Resource
    private CategoryMapper categorymapper;

    /**
     * 查询全部
     *
     * @return
     */
    public List<Category> selectAll(Category category) {
        return categorymapper.selectAll(category);
    }

    /**
     * 分页查询+条件查询
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    public PageInfo selectPage(Category category, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Category> list = categorymapper.selectAll(category);
        return PageInfo.of(list);
    }

    /**
     * 新增
     * @param category
     */
    public void add(Category category){
        categorymapper.add(category);
    }

    /**
     * 根据id查询
     * @return
     */
    public Category selectById(Category category){
        return categorymapper.selectById(category);
    }

    /**
     * 修改
     * @param category
     */
    public void update(Category category){
        categorymapper.update(category);
    }

    /**
     * 删除
     * @param id
     */
    public void delete(Integer id){
        categorymapper.delete(id);
    }

    /**
     * 批量删除
     * @param ids
     */
    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids) {
            categorymapper.delete(id);
        }
    }
}
